﻿using DotNetCore.CAP;

namespace HZY.Api.Admin.Controllers;

[AllowAnonymous]
public class TestController(IServiceProvider serviceProvider, ICapPublisher publisher)
    : AdminControllerBase(serviceProvider), ICapSubscribe
{
    /// <summary>
    /// 测试接口
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public string Index()
    {
        // throw new ArgumentException("123");
        // throw new TimeoutException("123");
        for (int i = 0; i < 10 * 1000; i++)
        {
            publisher.Publish("Test.Test", "发布了第 " + i + " 条消息");
        }

        return "Hello World";
    }

    // 消费
    [CapSubscribe("Test.Test")]
    public void Test(string data)
    {
        Console.WriteLine("消费成功！！！=== " + data);
    }
}